﻿using Outlook = Microsoft.Office.Interop.Outlook;
using Microsoft.Office.Tools.Ribbon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UDMOutlook.Entity;

namespace UDMOutlook
{
    public partial class Menu
    {
        private void Menu_Load(object sender, RibbonUIEventArgs e)
        {

        }
        
        private void btnRegistAI_Click(object sender, RibbonControlEventArgs e)
        {
            Outlook.Application outlookApp = new Outlook.Application();
            Outlook.MailItem mailItem = outlookApp.ActiveInspector().CurrentItem as Outlook.MailItem;

            if (mailItem != null)
            {
                // 添加抄送人
                Outlook.Recipients recipients = mailItem.Recipients;
                Outlook.Recipient recipient = recipients.Add("cex@uaes.com");
                recipient.Type = (int)Outlook.OlMailRecipientType.olCC;
                recipients.ResolveAll();

                // 在邮件主题前添加前缀
                if (!string.IsNullOrEmpty(mailItem.Subject))
                {
                    mailItem.Subject = "[AI-DCM数据集成] " + mailItem.Subject;
                }
                else
                {
                    mailItem.Subject = "[AI-DCM数据集成]";
                }

                mailItem.Save();
                MessageBox.Show("邮件已更新！");
            }
            else
            {
                MessageBox.Show("请先打开一封邮件再操作！");
            }
        }

        private void btnShowAI_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {
                Outlook.Inspector inspector = e.Control.Context as Outlook.Inspector;
                if (inspector?.CurrentItem is Outlook.MailItem mail)
                {
                    // 添加抄送人
                    if (!mail.CC.Contains("cex@uaes.com"))
                    {
                        mail.CC += (mail.CC.Length > 0 ? ";" : "") + "cex@uaes.com";
                    }

                    // 添加主题前缀
                    if (!mail.Subject.StartsWith("[AI-DCM数据集成]"))
                    {
                        mail.Subject = "[AI-DCM数据集成]" + mail.Subject;
                    }

                    mail.Save();
                    MessageBox.Show("AI参数已自动填充");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"操作失败: {ex.Message}");
            }
        }
    }
}
